package com.zly.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.zly.entity.Absence;
import com.zly.entity.Dorm;
import com.zly.entity.Houseparent;
import com.zly.entity.StudentInfoManager;
import com.zly.service.DormService;
import com.zly.service.impl.DormServiceImpl;

public class AddDormManager extends ActionSupport {

	/**
	 * 反序列化
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 添加宿舍管理员
	 * 
	 * @return
	 */
	public String addDormManager() {
		// 用request获取值
		HttpServletRequest request = ServletActionContext.getRequest();
		String hUName = request.getParameter("hUName");
		String hPwd = request.getParameter("hPwd");
		String hSex = request.getParameter("hSex");
		String hPhone = request.getParameter("hPhone");
		String hDorm = request.getParameter("hDorm");
		String hName = request.getParameter("hName");
		// 调用service层实现数据的保存
		DormService<Houseparent> dormService = new DormServiceImpl<>();
		Houseparent houseparent = new Houseparent(0, hUName, hPwd, hSex, hPhone, hDorm, hName);
		dormService.save(houseparent);
		return SUCCESS;
	}
	/**
	 * 添加学生信息
	 * @return
	 */
	public String addStu() {
		// 用request获取值
		HttpServletRequest request = ServletActionContext.getRequest();
		String stuId = request.getParameter("stuId");
		int stuIdInt = Integer.parseInt(stuId);
		String stuName = request.getParameter("stuName");
		String stuPwd = request.getParameter("stuPwd");
		String stuSex = request.getParameter("stuSex");
		String stuDrom = request.getParameter("stuDrom");
		String stuDromId = request.getParameter("stuDromId");
		int stuDromIdInt = Integer.parseInt(stuDromId);
		String stuPhone = request.getParameter("stuPhone");
		// 调用service层实现数据的保存
		DormService<StudentInfoManager> dormService = new DormServiceImpl<>();
		StudentInfoManager studentInfoManager = new StudentInfoManager(0, stuIdInt, stuName, stuPwd, stuSex, stuDrom, stuDromIdInt, stuPhone);
		System.out.println(studentInfoManager);
		dormService.save(studentInfoManager);
		return SUCCESS;
	}
	/**
	 * 添加宿舍楼
	 * @return
	 */
	public String addTower() {
		// 用request获取值
		HttpServletRequest request = ServletActionContext.getRequest();
		String dormId = request.getParameter("dormId");
		int dormIdInt = Integer.parseInt(dormId);
		String dormName = request.getParameter("dormName");
		String dormMess = request.getParameter("dormMess");
		// 调用service层实现数据的保存
		DormService<Dorm> dormService = new DormServiceImpl<>();
		Dorm dorm = new Dorm(dormIdInt, dormName, dormMess);
		dormService.save(dorm);
		return SUCCESS;
	}
	/**
	 * 添加缺勤
	 * @return
	 */
	public String addAbs() {
		// 用request获取值
		HttpServletRequest request = ServletActionContext.getRequest();
		String absenceDate = request.getParameter("absenceDate");
		String stuId = request.getParameter("stuId");
		int stuIdInt = Integer.parseInt(stuId);
		String stuName = request.getParameter("stuName");
		String dorm = request.getParameter("dorm");
		String dormId = request.getParameter("dormId");
		int dormIdInt = Integer.parseInt(dormId);
		String remark = request.getParameter("remark");
		// 调用service层实现数据的保存
		DormService<Absence> dormService = new DormServiceImpl<>();
		Absence absence = new Absence(0, absenceDate, stuIdInt, stuName, dorm, dormIdInt, remark);
		dormService.save(absence);
		return SUCCESS;
	}

}
